package cn.yuanqiao.archive.archiveFormSave.domain;

import cn.yuanqiao.common.annotation.Excel;
import cn.yuanqiao.common.core.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 归档申请单对象 YQDA_ARCHIVE_FORM
 *
 * @author yuanqiao
 * @date 2023-07-26
 */
public class YqdaArchiveForm extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 表单ID
     */
    private String formId;

    /**
     * 表单批次号
     */
    @Excel(name = "表单批次号")
    private String formNo;

    /**
     * 分单号
     */
    @Excel(name = "分单号")
    private String splitNo;

    /**
     * 档案ID
     */
    @Excel(name = "档案ID")
    private String archiveId;

    /**
     * 门类ID
     */
    @Excel(name = "门类ID")
    @JsonFormat(shape = JsonFormat.Shape.STRING)//转化成string传到前端
    private Long categoryId;

    /**
     * 门类ID
     */
    @Excel(name = "门类ID")
    private String categoryIdaf;

    /**
     * 状态
     */
    @Excel(name = "状态")
    private String state;

    /**
     * 发起人
     */
    @Excel(name = "发起人")
    private String submitUser;

    /**
     * 发起人ID
     */
    private String submitUserId;

    /**
     * 发起时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @Excel(name = "发起时间", width = 30, dateFormat = "yyyy-MM-dd")
    //@JSONField(format = "yyyy-MM-dd")
    private Date submitTime;

    /**
     * 发起部门
     */
    @Excel(name = "发起部门")
    private String submitDept;

    private String REMARK;

    private String daType;

    private String workflowId;

    private String workflowFormId;

    private String submitDeptId;

    private String userId;

    private String tenantCode;

    private String subTableName;

    public String getCategoryIdaf() {
        return categoryIdaf;
    }

    public void setCategoryIdaf(String categoryIdaf) {
        this.categoryIdaf = categoryIdaf;
    }

    public String getSubTableName() {
        return subTableName;
    }

    public void setSubTableName(String subTableName) {
        this.subTableName = subTableName;
    }

    public String getTenantCode() {
        return tenantCode;
    }

    public void setTenantCode(String tenantCode) {
        this.tenantCode = tenantCode;
    }

    public String getSubmitDeptId() {
        return submitDeptId;
    }

    public void setSubmitDeptId(String submitDeptId) {
        this.submitDeptId = submitDeptId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getWorkflowId() {
        return workflowId;
    }

    public void setWorkflowId(String workflowId) {
        this.workflowId = workflowId;
    }

    public String getWorkflowFormId() {
        return workflowFormId;
    }

    public void setWorkflowFormId(String workflowFormId) {
        this.workflowFormId = workflowFormId;
    }

    public void setFormId(String formId) {
        this.formId = formId;
    }

    public String getFormId() {
        return formId;
    }

    public void setFormNo(String formNo) {
        this.formNo = formNo;
    }

    public String getFormNo() {
        return formNo;
    }

    public void setSplitNo(String splitNo) {
        this.splitNo = splitNo;
    }

    public String getSplitNo() {
        return splitNo;
    }

    public void setArchiveId(String archiveId) {
        this.archiveId = archiveId;
    }

    public String getArchiveId() {
        return archiveId;
    }

    @Override
    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }

    @Override
    public Long getCategoryId() {
        //return categoryId;
        if (categoryIdaf!= null){
            return Long.valueOf(categoryIdaf);
        }else {
            return categoryId;
        }
    }

    public Long getCategoryIdOrg() {
        return categoryId;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getState() {
        return state;
    }

    public void setSubmitUser(String submitUser) {
        this.submitUser = submitUser;
    }

    public String getSubmitUser() {
        return submitUser;
    }

    public void setSubmitUserId(String submitUserId) {
        this.submitUserId = submitUserId;
    }

    public String getSubmitUserId() {
        return submitUserId;
    }

    public void setSubmitTime(Date submitTime) {
        this.submitTime = submitTime;
    }

    public Date getSubmitTime() {
        return submitTime;
    }

    public void setSubmitDept(String submitDept) {
        this.submitDept = submitDept;
    }

    public String getSubmitDept() {
        return submitDept;
    }

    public String getREMARK() {
        return REMARK;
    }

    public void setREMARK(String REMARK) {
        this.REMARK = REMARK;
    }

    public String getDaType() {
        return daType;
    }

    public void setDaType(String daType) {
        this.daType = daType;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("formId", formId)
                .append("formNo", formNo)
                .append("splitNo", splitNo)
                .append("archiveId", archiveId)
                .append("categoryId", categoryId)
                .append("state", state)
                .append("submitUser", submitUser)
                .append("submitUserId", submitUserId)
                .append("submitTime", submitTime)
                .append("submitDept", submitDept)
                .append("REMARK", REMARK)
                .append("daType", daType)
                .append("workflowId", workflowId)
                .append("workflowFormId", workflowFormId)
                .append("submitDeptId", submitDeptId)
                .append("userId", userId)
                .append("tenantCode", tenantCode)
                .append("subTableName", subTableName)
                .toString();
    }

    public Map<String, Object> toProcessMap() {
        Map<String, Object> map = new HashMap<>();

        // 使用反射获取实体类的字段信息
        Class<?> clazz = this.getClass();
        Field[] fields = clazz.getDeclaredFields();

        try {
            // 遍历所有字段，获取字段名和字段值，并存储到 Map 中
            for (Field field : fields) {
                field.setAccessible(true); // 设置字段可访问，即使是私有字段也可以获取值
                String fieldName = field.getName();
                Object fieldValue = field.get(this); // 获取字段的值
                map.put(fieldName, fieldValue);
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return map;
    }
}
